/**
 * 
 */
package com.ginger.countdown;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @Description: 临行前检查
 * @author 姜锋
 * @date 2018年8月20日 下午2:00:47 
 * @version V1.0   
 *
 */
public  class CheckStartUp {
	
	private static List<MonitorCenter> stationList;
	private static CountDownLatch countDown;
	
	
	public CheckStartUp() {
	}
	
	public static boolean checkAllStations() throws Exception {
		countDown = new CountDownLatch(3);
		stationList = new ArrayList<>();
		stationList.add(new StationBeiJingGinger(countDown));
		stationList.add(new StationJiLinChangChun(countDown));
		stationList.add(new StationXinZhouDaJiangJun(countDown));
		Executor executer =  Executors.newFixedThreadPool(stationList.size());
		
		for (MonitorCenter center : stationList) {
			executer.execute(center);
		}
		//等待线程执行完成
		countDown.await();
		for (MonitorCenter monitorCenter : stationList) {
			if(!monitorCenter.isOk()) {
				return false;
			}
				
			
		}
		return true;
	}
	public static void main(String[] args) throws Exception {
		
		boolean result = checkAllStations();
		System.out.println("本次对危险品检查结果为........."+result);
	}
}
